package ru.ipccenter.jpa;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Krems
 */
@Entity
@Table(name="samba.users")
@NamedQueries({
@NamedQuery(name="login", 
        query="Select L.password "
        + "from LoginEntity L "
        + "where L.login = :login"),
@NamedQuery(name="loginExist", 
        query="Select L.id "
        + "from LoginEntity L "
        + "where L.login = :login")
})
public class LoginEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(columnDefinition="VARCHAR(256)")
    private String login;
    @Column(columnDefinition="VARCHAR(256)")
    private String password;

    public LoginEntity(){};
    
    public LoginEntity(String login, String password) {
        this.login = login;
        this.password = password;
    }
    
    public Long getId() {
        return id;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getLogin() {
        return login;
    }

    public String getPassword() {
        return password;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LoginEntity)) {
            return false;
        }
        LoginEntity other = (LoginEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ru.ipccenter.jpa.LoginEntity[ id=" + id + " ]";
    }
    
}
